import os
import sys

vars = Variables()
vars.Add(BoolVariable("optimized", "Set to 1 to build for release", 0))
vars.Add(PathVariable("PREFIX", "Install prefix", "/usr" if sys.platform != "win32" else "."))

env = Environment(variables=vars)
env["PREFIX"] = os.path.abspath(env["PREFIX"])
env.Alias("install", "$PREFIX")

if sys.platform != "win32" :
    if env["optimized"] :
        env.AppendUnique(CCFLAGS=["-O3", "-Wall", "-DNDEBUG"])
    else :
        env.AppendUnique(CCFLAGS=["-g", "-Wall"])
else :
    if env["optimized"] :
        env.AppendUnique(CCFLAGS=["/EHsc", "/Ox", "/MD"])
        env.AppendUnique(CPPDEFINES=["WIN32", "_CRT_SECURE_NO_DEPRECATE"])
    else :
        env.AppendUnique(CCFLAGS=["/EHsc", "/GS", "/MDd"])
        env.AppendUnique(CPPDEFINES=["WIN32"])
    
    env.AppendUnique(LINKFLAGS="/subsystem:windows")
    env.AppendUnique(LIBPATH=os.environ.get("LIB", "").split(';'))
    env.AppendUnique(CPPPATH=os.environ.get("INCLUDE", "").split(';'))

if "PKG_CONFIG_PATH" in os.environ :
    env["ENV"]["PKG_CONFIG_PATH"] = os.environ["PKG_CONFIG_PATH"]

Export("env")

defaults = []
defaults.append(SConscript("lib/SConstruct"))
defaults.append(SConscript("gui/SConstruct"))
Default(defaults)
